<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<title>DAMN Asset Manager</title>

  <link href="/static/reset.css" rel="stylesheet" type="text/css" />
  <link rel="stylesheet" href="/static/ui-darkness/jquery-ui-1.8rc3.custom.css" type="text/css" media="all" />
  <link href="/static/style.css" rel="stylesheet" type="text/css" />


  <script src="/static/js/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
  <script src="/static/js/jquery/ahpi.imgload.js" type="text/javascript"></script>
  <script src="/static/js/jquery/mousewheel.js" type="text/javascript"></script>
  
  <script src="/static/js/ui/jquery-ui.js" type="text/javascript"></script>

  <script src="/static/js/jlayout/jquery.layout.js" type="text/javascript"></script>

  <script src="/static/js/jstree/jquery.jstree.js" type="text/javascript"></script> 


  <script src="/static/js/webgl/CS.js" type="text/javascript"></script>
  <script src="/static/js/webgl/glMatrix-0.9.4.min.js" type="text/javascript"></script>
  <script src="/static/js/webgl/rendermanager.js" type="text/javascript"></script>
  <script src="/static/js/webgl/genmesh.js" type="text/javascript"></script>
  <script src="/static/js/damn/preview.js" type="text/javascript"> </script>
  

  <script src="/static/js/damn/log.js" type="text/javascript"> </script>
  <script src="/static/js/damn/loginmgr.js" type="text/javascript"> </script>
  <script src="/static/js/damn/assetmgr.js" type="text/javascript"> </script>
  <script src="/static/js/damn/ui/browse.js" type="text/javascript"> </script>
  <script src="/static/js/damn/ui/search.js" type="text/javascript"> </script>
  <script src="/static/js/damn/ui/layout.js" type="text/javascript"> </script>
  <script src="/static/js/damn/ui/preview.js" type="text/javascript"> </script>
  <script src="/static/js/damn/ui/content.js" type="text/javascript"> </script>
  <script src="/static/js/damn/ui/formats.js" type="text/javascript"> </script>
  <script src="/static/js/damn/ui/metadata.js" type="text/javascript"> </script>
  <script src="/static/js/damn/ui/tags.js" type="text/javascript"> </script>
  <script src="/static/js/damn/ui/collections.js" type="text/javascript"> </script>
  
  <script>

  $(document).ready(function () {	

	DAMN.Log.init($(".ui-layout-south"));	

	DAMN.LoginMananger.init();

	$(".tabs").tabs();

	var $tabs = $(".tabs-closable").tabs({
		tabTemplate: '<li><a href="#{href}">#{label}</a><span class="ui-icon ui-icon-close">Remove Tab</span></li>'
		,select: function(event, ui) 
		{ 
			DAMN.LoginMananger.HideTab();
      
			//Set currently selected node on previous tab.
			var sel = DAMN.GetTab($(".tabs-closable"), $(".tabs-closable").tabs('option', 'selected'));
			//If any...
			if (typeof sel.data('Content') != "undefined" || sel.data('Content') != null) {
				sel.data('Content').selectedNode = $($.jstree._focused().selected);
			}

			//Select node of current tab.
			var node = $(ui.panel).data('Content').selectedNode;
			if (node != null) {
				$.jstree._focused().select_node(node);
			}
			
		}
	}).find(".ui-tabs-nav").sortable({axis:'x', items: 'li:not(.ui-state-disabled)'}); //TODO why doesnt this ignore Main?


	$('.tabs-closable span.ui-icon-close').live('click', function() {
		var index = $('li', $(".tabs-closable")).index($(this).parent());
		if (DAMN.GetContent($(this).parent()).closeable) {
			$(".tabs-closable").tabs('remove', index);
		}
	});
	

	DAMN.Layout();
	
	DAMN.Preview.AttachTo($("#ui-layout-east-tabs1"));
	DAMN.Formats.AttachTo($("#ui-layout-east-tabs1"));
	
	DAMN.MetaData.AttachTo($("#ui-layout-east-tabs2"));
	DAMN.Tags.AttachTo($("#ui-layout-east-tabs2"));
	DAMN.Collections.AttachTo($("#ui-layout-east-tabs2"));
	
	DAMN.Search.AttachTo($("#ui-layout-west-tabs"));
	DAMN.Browser.AttachTo($("#ui-layout-west-tabs"));
	

	var main = new DAMN.Content('Main');
	main.AttachTo($("#ui-layout-center-tabs"));
	main.closeable = false;
	$('li a[href$="tabs-Content-Main"]:parent').parent().children().remove("span");
	//$('li a[href$="tabs-Content-Main"]:parent').parent().addClass('ui-state-disabled'); //TODO see above.

	DAMN.LoginMananger.AttachTo($("#ui-layout-center-tabs"));
	
	
	var query = window.location.search;
  if (query.substring(0, 1) == '?') {
    query = query.substring(1);
  }
  var data = query.split(',');
  for (i = 0; (i < data.length); i++) {
    var tmp = unescape(data[i]).split('=');
    data[tmp[0]] = tmp[1];
    DAMN.Log.debug("DAMN: GET "+tmp[0]+': '+tmp[1]);
  }

  if (data.assetId) {
    DAMN.Browser.FireOnLoad(function(){
      DAMN.Browser.Select(data['assetId']);
	});
  }
  
  /*
  CS.Log.error = DAMN.Log.error.bind(DAMN.Log);
	CS.Log.warn = DAMN.Log.warn.bind(DAMN.Log);
  
  if (data.noWebGL) CS.hasWebGLSupport = false;
  
  if (CS.hasWebGLSupport)
	 document.title = 'WebGL - DAMN';
*/

});

  </script>

  <!-- shaders -->
  <script id="shader-fs" type="x-shader/x-fragment"> 
  #ifdef GL_ES
  precision highp float;
  #endif
 
  varying vec2 vTextureCoord;
  varying vec3 vLightWeighting;
 
  uniform bool uUseTextures;
  uniform sampler2D uSampler;
 
  void main(void) {
     vec4 fragmentColor;
	   if (uUseTextures) 
     		fragmentColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
    	else 
     		 fragmentColor = vec4(1.0, 1.0, 1.0, 1.0);
     gl_FragColor = vec4(fragmentColor.rgb*vLightWeighting, fragmentColor.a);
	   //gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
  }
</script> 
 
<script id="shader-vs" type="x-shader/x-vertex"> 
  attribute vec3 aVertexPosition;
  attribute vec3 aNormals;
  attribute vec2 aTextureCoord;
 
  uniform mat4 uMVMatrix;
  uniform mat4 uPMatrix;
  uniform mat4 uNMatrix;
 
  uniform vec3 uAmbientLight;
  uniform vec3 uDirectionnalLight;
 
  varying vec2 vTextureCoord;
  varying vec3 vLightWeighting;
 
  void main(void) {
    vTextureCoord = aTextureCoord;
    vec4 transformedNormal = uNMatrix * vec4(aNormals, 1.0);
    vLightWeighting = uAmbientLight+uDirectionnalLight*max(dot(transformedNormal.xyz, vec3(1.0,1.0, 1.0)), 0.0);
	   // vLightWeighting = vec3(1,1,1);
	  gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
  }
</script>

</head>
<body>

  <div id="dialog-login" title="Log in" style="display:none;">
    <div id="dialog-login-content" title="">
    </div>
  </div>
  
  <div id="dialog-message" title="Message" style="display:none;">
    You don't have the permissions to do that!
  </div>
  
  <div id="dialog-preview" title="Preview" style="display:none;">
  </div>


  <div class="ui-layout-west">
      <div id="ui-layout-west-tabs" class="tabs" style="overflow: hidden; height: 99%;"><ul></ul></div>
  </div>
  
  <div class="ui-layout-south">
  </div>
  
  <div class="ui-layout-east">
      <div class="east-north">
        <div id="ui-layout-east-tabs1" class="tabs" style="min-height: 98%;"><ul></ul></div>
      </div>
      <div class="east-center">
        <div id="ui-layout-east-tabs2" class="tabs" style="height: 97%; overflow:hidden;"><ul></ul></div>
      </div>
  </div>
  
  <div class="ui-layout-center">
    <div id="ui-layout-center-tabs" class="tabs-closable" style="min-height: 99%;"> <ul></ul></div>
  </div> 
</body>
</html>
